package test;

import java.util.Scanner;

public class ccc {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n=scan.nextInt();
        int[] a=new int[n];
        int[] taked=new int[n];
        for(int i=0;i<n;i++){
            a[i]=scan.nextInt();
        }
        int k=n-1;
        int max=0;
        while(k>=0){
            int q=0;
            int count=0;
            for(int i=0;i<n*n;i++){
                int j=k+i;
                if(j>n-1) {
                    j = j % n;
                }
                if(taked[j]==0){q++;}
                if(q==a[j]&&taked[j]==0){
                    taked[j]=1;
                    q=0;
                    count+=a[j];

                }
            }
            taked=new int[n];
            k--;
            max= Math.max(max, count);

        }
        System.out.println(max);
        scan.close();
    }
}
